Manage departments and limits
DepartmentManager
Manage departments.
class yandex_b2b_go.department.DepartmentManager(client: Client)
Attribute
-
DepartmentLimitManager — manage the department limit.
limit: DepartmentLimitManager
Methods
- create — create a department.
- list — get a list of departments
- update — update the department.
- delete — deletes the department and all its subordinate (child) departments.
Create
Create a department.
async def create(department: Department) -> DepartmentCreateResponse
Parameter
department— data about a new department. The Department class.
If successful, returns the DepartmentCreateResponse class.
If the parameters are incorrect, the method returns the ValidationError error.
If the response code is not 200, an error is returned: ApiError.
Request example
import asyncio
from yandex_b2b_go import Client
from yandex_b2b_go import DepartmentManager
from yandex_b2b_go import typing, errors
TOKEN = '<your token>'
async def main():
client = Client(token=TOKEN)
department_manager = DepartmentManager(client=client)
try:
department = typing.Department(
name='Marketing department'
)
response_create = await department_manager.create(department=department)
...
except errors.ValidationError as e:
return str(e.args)
except errors.ApiError as e:
return e
asyncio.run(main())
List
Gets a list of departments.
async def list(
limit: Optional[int] = None,
offset: Optional[int] = None
) -> DepartmentListResponse
Parameters
limit— number of records to display. If this parameter is not specified, information about the first 100 records is returned.offset— number of skipped records. If this parameter is missing, information is returned starting from the first record.
If successful, returns the DepartmentListResponse class.
If the parameters are incorrect, the method returns the ValidationError error.
If the response code is not 200, an error is returned: ApiError.
Request example
import asyncio
from yandex_b2b_go import Client
from yandex_b2b_go import DepartmentManager
from yandex_b2b_go import typing, errors
TOKEN = '<your token>'
async def main():
client = Client(token=TOKEN)
department_manager = DepartmentManager(client=client)
try:
department_list = await department_manager.list(limit=100, offset=0)
...
except errors.ValidationError as e:
return str(e.args)
except errors.ApiError as e:
return e
asyncio.run(main())
Update
Update the department.
async def update(
department_id: str,
department: DepartmentUpdateRequest
) -> DepartmentUpdateResponse
Parameters
department_id— the department ID for which the information is updated.department— new department data, class DepartmentUpdateRequest.
If successful, returns the DepartmentUpdateResponse class.
If the parameters are incorrect, the method returns the ValidationError error.
If the response code is not 200, an error is returned: ApiError.
Request example
import asyncio
from yandex_b2b_go import Client
from yandex_b2b_go import DepartmentManager
from yandex_b2b_go import typing, errors
TOKEN = '<your token>'
async def main():
client = Client(token=TOKEN)
department_manager = DepartmentManager(client=client)
try:
department = typing.DepartmentUpdateRequest(
name='B2B marketing'
)
response_update = await department_manager.update(department_id='87e8...f646c', department=department)
...
except errors.ValidationError as e:
return str(e.args)
except errors.ApiError as e:
return e
asyncio.run(main())
Delete
Deletes the department and all subordinate (child) departments.
async def delete(department_id: str) -> DepartmentDeleteResponse
Parameter
department_id— the ID of the department that's used for deletion.
If the request is successful, the method returns the DepartmentDeleteResponse class.
If the parameters are incorrect, the method returns the ValidationError error.
If the response code is not 200, an error is returned: ApiError.
Request example
import asyncio
from yandex_b2b_go import Client
from yandex_b2b_go import DepartmentManager
from yandex_b2b_go import typing, errors
TOKEN = '<your token>'
async def main():
client = Client(token=TOKEN)
department_manager = DepartmentManager(client=client)
try:
response_delete = await department_manager.delete(department_id='87e8...646c')
...
except errors.ValidationError as e:
return str(e.args)
except errors.ApiError as e:
return e
asyncio.run(main())
DepartmentLimitManager
Manage department limits.
class yandex_b2b_go.departemnt.DepartmentLimitManager(client: Client)
Attribute
-
DepartmentTaxiLimitManager — manage the department limit for Taxi rides.
taxi: DepartmentTaxiLimitManager
DepartmentTaxiLimitManager
Manage the department's ride limit in the Taxi service.
class yandex_b2b_go.department.DepartmentTaxiLimitManager(client: Client)
Methods
Get
Returns the department's ride limit.
async def get(department_id: str) -> DepartmentBudget
Parameter
department_id— department ID that's used to request the limit.
If successful, returns the DepartmentBudget class.
If the parameters are incorrect, the method returns the ValidationError error.
If the response code is not 200, an error is returned: ApiError.
Request example
import asyncio
from yandex_b2b_go import Client
from yandex_b2b_go import DepartmentManager
from yandex_b2b_go import typing, errors
TOKEN = '<your token>'
async def main():
client = Client(token=TOKEN)
department_manager = DepartmentManager(client=client)
try:
department_limit_taxi = await department_manager.limit.taxi.get(department_id='87e8...646c')
...
except errors.ValidationError as e:
return str(e.args)
except errors.ApiError as e:
return e
asyncio.run(main())
Update
Changes the department's ride limit.
async def update(
department_id: str,
limit: DepartmentBudget
) -> DepartmentUpdateResponse
Parameters
department_id: the department ID to change the limit for.limit— updated information about the department's limit, class DepartmentBudget.
If successful, returns the DepartmentUpdateResponse class.
If the parameters are incorrect, the method returns the ValidationError error.
If the response code is not 200, an error is returned: ApiError.
Request example
import asyncio
from yandex_b2b_go import Client
from yandex_b2b_go import DepartmentManager
from yandex_b2b_go import typing, errors
TOKEN = '<your token>'
async def main():
client = Client(token=TOKEN)
department_manager = DepartmentManager(client=client)
try:
limit = typing.DepartmentBudget(budget=10000)
response_update = await department_manager.limit.taxi.update(department_id='87e8...646c', limit=limit)
...
except errors.ValidationError as e:
return str(e.args)
except errors.ApiError as e:
return e
asyncio.run(main())